package com.jack.concurrent.limit;

/**
 * Created by JackGe on 2017/7/10.
 */
public class ConcurrentFlow {

    private Ring<String, Passer> ring = new Ring<>();
    private FlowConfig config;

    public Passer enter(String key) {
        Passer passer = this.ring.get(key);
        if (null == passer) {
            passer = new Passer();
            passer.setConfig(this.config);
            Passer exist = this.ring.put(key, passer);
            if (exist != null) {
                passer = exist;
            }
        }
        return passer;
    }

    public FlowConfig getConfig() {
        return config;
    }

    public ConcurrentFlow setConfig(FlowConfig config) {
        this.config = config;
        return this;
    }
}
